#ifndef __SCREEN_MGR_H__
#define __SCREEN_MGR_H__

#include "Screen.h"

#include <SFML/Graphics.hpp>
#include <Uncopyable.h>

#include <list>

#define SCREEN_MGR ScreenMgr::instance()

class ScreenMgr : Uncopyable
{
public:
	~ScreenMgr();															// Destructor.
	static ScreenMgr* instance();											// Singleton accessor method.

	void draw();															// Draws the active screen.
	void setWindow(sf::RenderWindow* win);									// Sets the RenderWindow to draw to.
	void setLoadingScreen(Screen* screen);									// Sets the loading screen to use game-wide.
	void update(float dt);													// Updates the active screen.

	int getScreenWidth();													// Returns the width of the screen.
	int getScreenHeight();													// Returns the height of the screen.
	Vector2D getScreenCenter();												// Returns the point at the center of the sreen.

	void popScreen();														// Pops the top-most screen on the stack.
	void pushScreen(Screen* newScreen, bool keepUpdating = false);			// Pushes a new screen onto the stack.
	void replaceScreen(Screen* newScreen);									// Replaces the active screen.
	
	void keyPressed(sf::Keyboard::Key key);									// Called when a key is pressed and the screen is foremost.
	void mouseUp(sf::Mouse::Button button, sf::Vector2i mousePosition);		// Called when a mouse button is released within the screen.
	void mouseDown(sf::Mouse::Button button, sf::Vector2i mousePosition);	// Called when a mouse button is pressed within the screen.
	void mouseMoved(sf::Vector2i newPosition);								// Called when the mouse is moved by the user.
private:
	ScreenMgr();															// Constructor.
	Screen* m_activeScreen;													// The active screen.
	Screen* m_loadingScreen;												// The chosen loading screen.

	sf::RenderWindow* m_renderWindow;										// The RenderWindow to draw the screen to.
	sf::Vector2i m_mousePosition;											// The current position of the mouse.

	static const sf::Time kMinLoadingScreenTime;

	std::list<std::pair<Screen*,bool>> m_screenStack;						// The stack of screens with boolean flags to keep them updating.
	std::list<Screen*> m_deadScreens;										// The list of screens to be removed on the next step.
};

#endif // __SCREEN_MGR_H__